xend: fix memory leak resulting in long garbage collector runs
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 5 Aug 2009 11:04:39 +0000 (12:04 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 5 Aug 2009 11:04:39 +0000 (12:04 +0100)
In the method xen.xend.XendStateStore.XendStateStore.load_state and
xen.xend.XendStateStore.XendStateStore.save_state the minidom objects
used to load/save the current state of a device type, can't be freed
by the python garbage collector after all references to the top node
are cleared, because of cyclic references between the DOM nodes. So
memory usage of xend increases after calling these methods.  To solve
this problem, the unlink() method must be called for a minidom object
before the last reference to the top node is cleared (see python
docs). This breaks the cyclic references, so the garbage collector can
free these objects.

Signed-off-by: juergen.gross@ts.fujitsu.com
tools/python/xen/xend/XendStateStore.py

index 245463fd4d9eadb9d947b81a9f85e91228df51c0..74767260f8d25c119ae4735bbbc03b070e1cd4e7 100644 (file)
@@ -147,6 +147,7 @@ class XendStateStore:
                     cls_dict[val_name] = bool(int(val_text))
             state[uuid] = cls_dict
 
+        dom.unlink()
         return state
 
     def save_state(self, cls, state):
@@ -226,5 +227,5 @@ class XendStateStore:
                     node.appendChild(val_node)
 
         open(xml_path, 'w').write(doc.toprettyxml())
-        
+        doc.unlink()